Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more properties controlling service reference code generation #10641

Merged
merged 4 commits into from
Jun 3, 2019

Conversation

dougbu
Copy link
Member

@dougbu dougbu commented May 30, 2019

also:

nits:

  • don't remove $(TargetFrameworks) when invoking OpenApiGetDocuments target (not necessary)
  • consolidate into a single $(GenerateOpenApiReferenceCodeDependsOn) property
  • rename task assembly and namespaces in Microsoft.Extensions.ApiDesription.Client to match the project
  • allow OpenApiGetDocuments targets to run in parallel if $(BuildInParallel) is enabled
  • remove $(OpenApiDefaultOutputDirectory) normalization; never concatenated with anything else
  • remove dangling GenerateServiceFileReferenceCode names

@dougbu dougbu requested a review from a team as a code owner May 30, 2019 05:14
RebaseOutputs="true"
RemoveProperties="%(ProjectReferenceWithConfiguration.GlobalPropertiesToRemove);TargetFrameworks;RuntimeIdentifier">
RemoveProperties="Configuration;Platform;RuntimeIdentifier;TargetFramework;TargetFrameworks">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rainersigwald is removing these properties sufficient?

And, am I missing something important in the shift from @(ProjectReferenceWithConfiguration) to using @(OpenApiProjectReference) items directly? (Without this, design-time builds would still have been broken and '$(OpenApiBuildReferencedProjects)' == 'false' would not work.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd definitely want to keep something like %(OpenApiProjectReference.GlobalPropertiesToRemove) in there as an escape hatch. This list looks ok to me, but there's always a risk of things changing (like when multitargeting was added) or user projects having their own custom dimensions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion! I added this to #4923 because I have other bits to do short-term.

@dougbu
Copy link
Member Author

dougbu commented May 30, 2019

@natemcmaster I'd of course appreciate any input you have on the MSBuild changes

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 30, 2019
<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" />
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" />
<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionClientAssemblyPath)" />
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionClientAssemblyPath)" />

<!--
Settings users may update as they see fit.
-->
<PropertyGroup>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennc do you have any input on the names of these user-visible properties?

Copy link
Contributor

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I wouldn't block on any of my comments.

<Target Name="_CreateOpenApiReferenceItemsForOpenApiProjectReferences"
AfterTargets="ResolveProjectReferences"
Condition="'$(DesignTimeBuild)' != 'true' AND '$(BuildingProject)' == 'true'">
<Target Name="_CreateOpenApiReferenceItemsForOpenApiProjectReferences" DependsOnTargets="ResolveProjectReferences">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have Condition="@(OpenApiProjectReference->Count()) != 0"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really doesn't matter because everything in this target no-ops when there's nothing worth doing. Let me know if you feel differently

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple is better, I agree with Doug.

</Target>

<Target Name="_TieInGenerateOpenApiReferenceCode"
BeforeTargets="BeforeCompile"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be CoreCompile. Would that allow users to do user things ™️ in BeforeCompile?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoreCompile is late because it comes after the MSBuild targets cache the list of references and source files involved in the compilation

Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard2.0</_ApiDescriptionClientAssemblyTarget>
<_ApiDescriptionClientAssemblyTarget
Condition="'$(MSBuildRuntimeType)' != 'Core'">net461</_ApiDescriptionClientAssemblyTarget>
<_ApiDescriptionClientAssemblyPath>$(MSBuildThisFileDirectory)/../tasks/$(_ApiDescriptionClientAssemblyTarget)/Microsoft.Extensions.ApiDescription.Client.dll</_ApiDescriptionClientAssemblyPath>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really relevant anymore? MSBuild supports netstandard2.0 everywhere .NET Core runs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the assembly has any dependencies that aren't in netstandard as implemented in .NET 4.7.2, I'd leave this in. Netstandard task assemblies are probably much more viable now that VS is on 4.7.2, but they've historically been a problem and splitting into core and full implementations has been required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mentioning it because we've been doing ns2.0 in Razor for a while now with no problems.

Since this is new code it should be fine as long as we test it in VS right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as long as it works in VS, command line msbuild.exe, and command line msbuild.exe from a Build Tools install of VS, you should be good to go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this to #4923 since the extra bits do no harm. This is all an implementation detail and it'll take time to do the necessary testing…

@@ -8,7 +8,7 @@
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Identity.Specification.Tests" ProjectPath="$(RepoRoot)src\Identity\Specification.Tests\src\Microsoft.AspNetCore.Identity.Specification.Tests.csproj" />
<ProjectReferenceProvider Include="Microsoft.Web.Xdt.Extensions" ProjectPath="$(RepoRoot)src\SiteExtensions\Microsoft.Web.Xdt.Extensions\src\Microsoft.Web.Xdt.Extensions.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DeveloperCertificates.XPlat" ProjectPath="$(RepoRoot)src\Tools\FirstRunCertGenerator\src\Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.ApiDescription.Tasks" ProjectPath="$(RepoRoot)src\Mvc\Extensions.ApiDescription.Client\src\Microsoft.Extensions.ApiDescription.Client.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.ApiDescription.Client" ProjectPath="$(RepoRoot)src\Mvc\Extensions.ApiDescription.Client\src\Microsoft.Extensions.ApiDescription.Client.csproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing some necessary context here, but I don't really get the point of renaming an assembly containing tasks to not be suffixed with .Tasks.

Is the metapoint here that we want to separate the tasks used for client-gen from the tasks used inside server-projects?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my original point but I ended up not needing tasks in the server project and decided I preferred using the same name everywhere.

Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some minor comments here but nothing blocking.

<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" />
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" />
<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionClientAssemblyPath)" />
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionClientAssemblyPath)" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random observation: GetCurrentItems is a pretty generic name given that item is a common term in MSBuild. We might want to choose more specific names. I don't think GetFileReferenceMetadata is bad.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the suggestion to #4923

<!--
Options added to the code generator command line by default. Provides the default %(Options) metadata of
@(OpenApiReference) and @(OpenApiProjectReference) items.
-->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always really happy to see quality docs in MSBuild 👍


<!--
If 'true' (the default), generate code for @(OpenApiReference) and @(OpenApiProjectReference) items during
design-time builds. Otherwise, generate code only during a full build.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going with the name OpenApiGenerateCodeOnBuild would this become OpenApiGenerateCodeOnDesignTimeBuild?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about it but the sense is a bit different. @glennc and I decided this one was fine as-is. Could of course change it if users disagree.

<Target Name="_CreateOpenApiReferenceItemsForOpenApiProjectReferences"
AfterTargets="ResolveProjectReferences"
Condition="'$(DesignTimeBuild)' != 'true' AND '$(BuildingProject)' == 'true'">
<Target Name="_CreateOpenApiReferenceItemsForOpenApiProjectReferences" DependsOnTargets="ResolveProjectReferences">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple is better, I agree with Doug.

@@ -85,10 +79,9 @@
Condition="$(OpenApiGenerateAtDesignTime) OR ('$(DesignTimeBuild)' != 'true' AND '$(BuildingProject)' == 'true')"
Inputs="@(OpenApiReference)"
Outputs="%(OutputPath)">
<MSBuild BuildInParallel="$(BuildInParallel)"
Projects="$(MSBuildProjectFullPath)"
<MSBuild Projects="$(MSBuildProjectFullPath)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this idea with this call that we only want to call this once even with multi-targeting? If that's the case should we have a comment?

Basically I'm not sure why this is a separate invocation of MSBuild, a comment would help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is about running things once. And, sure, I'll add a comment

@dougbu dougbu force-pushed the dougbu/client.fixes.4924.6582.10508 branch from 25778bb to 154deaa Compare May 31, 2019 23:15
@dougbu dougbu force-pushed the dougbu/client.fixes.4924.6582.10508 branch from 154deaa to 35c789a Compare June 1, 2019 03:15
@dougbu
Copy link
Member Author

dougbu commented Jun 1, 2019

🆙📅 to add the comment @rynowak suggested. Also rebased on 'master' but deferred most other suggestions to #4923

- `$(OpenApiGenerateBeforeCompile)` controls if targets run before compile targets
  - #4924
  - also correct multiple invocations when project has multiple target frameworks
- `$(OpenApiBuildReferencedProjects)` controls whether `@(OpenApiProjectReference)` items build automatically
  - #6582

also:
- add symbols for Microsoft.Extensions.ApiDescription.Client task assembly
  - #10508
- unconditionally run `OpenApiGetDocuments` target in referenced projects
  - corrects compilation in design-time builds
  - no longer uses `@(ProjectReferenceWithConfiguration)`; referenced project chooses all property values

nits:
- don't remove `$(TargetFrameworks)` when invoking `OpenApiGetDocuments` target (not necessary)
- consolidate into a single `$(GenerateOpenApiReferenceCodeDependsOn)` property
- rename task assembly and namespaces in Microsoft.Extensions.ApiDesription.Client to match the project
- allow `OpenApiGetDocuments` targets to run in parallel if `$(BuildInParallel)` is enabled
- remove `$(OpenApiDefaultOutputDirectory)` normalization; never concatenated with anything else
- remove dangling `GenerateServiceFileReferenceCode` names
- make it clear these properties control code generation
- use "OnBuild" for consistency with properties elsewhere in ASP.NET Core
- remove "Default" from a comple of property names because commaents are pretty clear
- rename a few targets for consistency with the new properties
  - word "Reference" didn't add much
@dougbu dougbu force-pushed the dougbu/client.fixes.4924.6582.10508 branch from 35c789a to f1f5f2f Compare June 3, 2019 03:11
@dougbu dougbu merged commit 2567233 into master Jun 3, 2019
@ghost ghost deleted the dougbu/client.fixes.4924.6582.10508 branch June 3, 2019 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants